﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TeacherList.aspx.cs" Inherits="School_TeacherList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>教师排序</title>
    
    <link href="../Common/css/main.css" rel="stylesheet" type="text/css" />    
    <script type="text/javascript" src="../Common/Js/jquery.js"></script>
    <script type="text/javascript" src="../Common/Js/common.js"></script>
    <script type="text/javascript" src="../Common/Js/msg.js"></script>
    <script type="text/javascript" src="../Common/Js/xTree/dhtmlxcommon.js"></script>
    <script type="text/javascript" src="../Common/Js/xTree/dhtmlxtree.js"></script>
    <link href="../Common/css/dhtmlxtree.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript" >
    
    window.onload = InitTeacherTree;
    
    var activate = 0;
    var tree;

    function InitTeacherTree()
    {
        tree=new dhtmlXTreeObject('treeBox','100%','100%',0);
        tree.setImagePath('../Common/images/xTreeImgs/');
        
        var id, text;
        
        var iOthersRoot = 0;                //其他姓名结点(固定值，取-100)
        var iLastRootId = 0;                //上一次建立的姓名结点ID
        var strLastRootName = "";        //上一次建立的姓名结点名称
        PageMethods.InitTeacherList(function(succ)
        {
            if (succ.length > 0)
            {
                for(var j = 0; j < succ.length; j++)
                {
                    if (succ[j].TeachNamePinYin == null || succ[j].TeachNamePinYin=="" || 
                        succ[j].TeachNamePinYin < "A" || succ[j].TeachNamePinYin>"Z")
                    {
                        if (iOthersRoot == 0)
                        {
                            iOthersRoot = -100;
                            tree.insertNewChild(0, iOthersRoot ,"其他", 0,"orgClose.png","organization.png","orgClose.png",""); 
                        }  
                        
                        tree.insertNewChild(-100,succ[j].RID,succ[j].TeachName,0,"group.gif","group.gif","group.gif","");                  
                    }
                    else
                    {
                        if (succ[j].TeachNamePinYin != strLastRootName)
                        {
                            strLastRootName = succ[j].TeachNamePinYin;
                            --iLastRootId;
                            
                            tree.insertNewChild(0,iLastRootId ,strLastRootName, 0 ,"orgClose.png","organization.png","orgClose.png","");                            
                        }
                        
                        tree.insertNewChild(iLastRootId,succ[j].RID,succ[j].TeachName,0,"group.gif","group.gif","group.gif","");
                    }
                }
                
                tree.closeAllItems(0);
                tree.setOnDblClickHandler(treeOnDbClick);
                
            }
                    
        },function(err)
        {
        	self.parent.showMassgeBox("提示","获取教师信息失败，请刷新后重试",1,null); 
        })
    }
    
    //双击事件
    function treeOnDbClick(id)
    {
        if (id > 0)
        {
            var iCauseID = self.parent.currCauseID;
            if (iCauseID == 0)
            {
                self.parent.showMassgeBox("提示","请选择课程",1,null); 
                return;
            }
            
            
            PageMethods.InsertTeacherToCause(id,iCauseID,function(succ)
            {
                if (succ == -1)
                {
                   self.parent.frames["right"].IsExistTeacher(1);
                   return;
                }
                else
                { 
                    //重新绑定中间教师数据
                    self.parent.frames["right"].Bind();
                }
            })             
        }
    }

    </script>
    
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
         <ContentTemplate>
            <div class="teacherTreeBox">
                    <div class="treeMain">
                         <div style="height:95%; width:170px; overflow:auto;" id="treeBox"></div>
	                </div>
            </div>  
         </ContentTemplate>
        </asp:UpdatePanel>
     </form>
</body>
</html>
